package com.zzyl;

import cn.hutool.json.JSONUtil;
import com.zzyl.common.constant.Constants;
import com.zzyl.nursing.domain.DeviceData;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class Redis {
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 测试字符串类型的数据
     */
    @Test
    public void testString() {
        redisTemplate.opsForValue().set("name", "张三");
        System.out.println(redisTemplate.opsForValue().get("name"));
        redisTemplate.opsForValue().set("age", 18);
        System.out.println(redisTemplate.opsForValue().get("age"));

    }
    /**
     * 测试hash类型
     */
    @Test
    public void testHash() {
        redisTemplate.opsForHash().put("user", "name", "张三");
        System.out.println(redisTemplate.opsForHash().get("user", "name"));
        redisTemplate.boundHashOps("user").put("age", 18);
        System.out.println(redisTemplate.boundHashOps("user").get("age"));
    }
    /**
     * 测试列表类型
     */
    @Test
    public void testList() {
        String deviceId = "688c18e0d582f20018415735_watch02";
        String jsonstr = JSONUtil.toJsonStr(redisTemplate.opsForHash().get(Constants.IOT_DEVICE_LAST_DATA, deviceId));
        List<DeviceData> list = JSONUtil.toList(jsonstr, DeviceData.class);

        System.out.println(list);
    }

}
